package examp

import (
	"fmt"
)

// Player 接口
type Player interface {
	Play(source string)
}

// Play 播放
func Play(source, mtype string) {
	var p Player
	switch mtype {
	case "MP3":
		p = &MP3Player{}
	case "WAV":
		p = &WAVPlayer{}
	default:
		fmt.Println("Unsupported music type", mtype)
		return
	}
	/*// 向下转型 if
	if play, ok := p.(*MP3Player); ok {
		play.Play(source)
	}
	// 另一种 switch
	switch t := p.(type) {
	case *MP3Player:
		t.Play(source)
	}*/

	p.Play(source)
}
